#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+10;
int a[N];
int ql[N],qr[N],qidx[N];
int bl[N];
bool cmp(int x,int y){
    return bl[ql[x]] < bl[ql[y]] || bl[ql[x]] == bl[ql[y]] && qr[x] < qr[y];
}
vector<int> factors[N];
long long ans[N];
int n,m;
namespace P1{
    int t1[N],t2[N];
    struct segment_tree{
        vector<pair<int,int>> val[N<<2];
        void update(int now,int l,int r,int x,int y,pair<int,int> v){
            if(x <= l && r <= y){
                val[now].push_back(v);
                return;
            }
            int mid = (l + r)/2;
            if(x <= mid){
                update(now<<1,l,mid,x,y,v);
            }else{
                update(now<<1|1,mid+1,r,x,y,v);
            }
        }
    }sg1,sg2;
    pair<int,int> S1[N],S2[N];
    int sp1,sp2;
    void dfs(int now,int l,int r){
        int osp1 = sp1,osp2 = sp2;
        for(pair<int,int> p1 : sg1.val[now]){
            S1[++sp1] = p1;
        }
        for(pair<int,int> p2 : sg2.val[now]){
            S2[++sp2] = p2;
        }
        if(l == r){
            t1[a[l]]++;
            for(int v : factors[a[l]]){
                t2[v]++;
            }
            int r1 = t2[a[l]],r2 = t2[a[l + 1]];
            for(int v : factors[a[l]]){
                r1 += t1[v];
            }
            for(int v : factors[a[l + 1]]){
                r2 += t2[v];
            }
            for(int i = 1;i<=sp1;i++){
                ans[S1[i].first] += S1[i].second*r1;
            }
            for(int i = 1;i<=sp2;i++){
                ans[S2[i].first] += S2[i].second*r2;
            }
            return;
        }
        int mid = (l + r)/2;
        dfs(now<<1,l,mid);
        dfs(now<<1|1,mid+1,r);
        sp1 = osp1;
        sp2 = osp2;
    }
}

int ma = 0;
namespace P2{
    int t1[N];
    bool f[N];
    struct command{
        int l,r,p,w;
    };
    vector<command> val[N];
    int su[N];
    void solve(){
        int lmt = sqrt(ma);
        for(int i = 1;i<=n;i++){
            for(int v : factors[a[i]]){
                t1[v]++;
            }
            if(a[i] >= lmt){
                for(int j = a[i];j <= ma;j += a[i]){
                    t1[j]++;
                }
            }else{
                f[a[i]] = 1;
            }
            for(command c : val[i]){
                for(int j = c.l;j <= c.r;j++){
                    ans[c.p] += c.w * t1[a[j]];
                }
            }
        }
        for(int j = 1;j <= lmt;j++){
            if(!f[j]){
                continue;
            }
            memset(su,0,sizeof(int)*n);
            for(int i = 1;i<=n;i++){
                su[i] = su[i - 1] + (a[i] % j == 0);
            }
            int res = 0;
            for(int i = 1;i<=n;i++){
                if(a[i] == j){
                    res++;
                }
                for(command c: val[i]){
                    ans[c.p] += c.w * (su[c.r] - su[c.l - 1])*res;
                }
            }
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i  = 1;i<=n;i++){
        cin >> a[i];
        ma = max(a[i],ma);
    }
    for(int i = 1;i<=m;i++){
        cin>>ql[i]>>qr[i];
        qidx[i] = i;
    }
    for(int j = 1;j <= ma;j++){
        for(int i = j;i <= ma;i += j){
            factors[i].push_back(j);
        }
    }
    int block = sqrt(n);
    int tot = n / block + (n % block != 0);
    for(int i = 1;i<=tot;i++){
        int lp = (i - 1)*block + 1,rp  = min(i * block,n);
        for(int j = lp;j <= rp;j++){
            bl[j] = i;
        }
    }
    sort(qidx + 1,qidx + 1 + m,cmp);
    int cl = 1,cr = 1;
    // r -> l;
    for(int p = 1;p <= m;p++){
        int l = ql[qidx[p]],r = qr[qidx[p]];
        if(cr < r){
            P1::sg2.update(1,1,n,cr,r - 1,{qidx[p],1});
            P2::val[cl - 1].push_back({cr + 1,r,qidx[p],-1});
            cr = r;
        }
        if(cl > l){
            P1::sg1.update(1,1,n,l,cl - 1,{qidx[p],-1});
            P2::val[cr].push_back({l,cl - 1,qidx[p],1});
            cl = l;
        }
        if(cr > r){
            P1::sg2.update(1,1,n,r,cr - 1,{qidx[p],-1});
            P2::val[cl - 1].push_back({r + 1,r,qidx[p],1});
            cr = r;
        }
        if(cl < l){
            P1::sg2.update(1,1,n,cl,l - 1,{qidx[p],1});
            P2::val[cr].push_back({cl,l - 1,qidx[p],-1});
            cl = l;
        }
    }
    P2::solve();
    P1::dfs(1,1,n);
    for(int i = 1;i<=n;i++){
        ans[qidx[i]] += ans[qidx[i - 1]];
    }
    for(int i = 1;i<=m;i++){
        cout<<(ans[i] + qr[i] - ql[i] + 1)<<'\n';
    }
}